<template>
	<!-- 登录界面 完成 -->
	<view class="container">
		<view class="form">

			<!-- 背景1 -->
			<view class="bg"
				:style="{backgroundImage:(currentBackground === 'bg1'? ImageBg.backgroundImage1 : ImageBg.backgroundImage2 )}">
				<!-- 头部 -->
				<view class="head">
					<view :class="navId==='login'?(currentBackground === 'bg1'?'active1': 'active2'):'unactive'"
						@click="itemclick('login')">
						账号登录
					</view>
					<view :class="navId==='register'?(currentBackground === 'bg1'?'active1': 'active2'):'unactive'"
						@click="itemclick('register')">
						验证码登录
					</view>
				</view>
				<!-- 登录表单 -->
				<view class="form-container">
					<uni-forms ref="loginRef" :rules="rules" :model="loginForm">
						<uni-forms-item class="form-item underLine" name="username">
							<uni-easyinput class="my_online" v-model="loginForm.username" placeholder="请输入账号"></uni-easyinput>
							<view :class="{'.loginonline1':bg === 'bg1', '.loginonline2':bg === 'bg2'}">
							</view>
						</uni-forms-item>

						<uni-forms-item class="form-item last-input" name="password">
							<uni-easyinput v-model="loginForm.password" placeholder="请输入密码"></uni-easyinput>
							<view :class="{'.loginonline1':bg === 'bg1', '.loginonline2':bg === 'bg2'}">
							</view>
						</uni-forms-item>
					</uni-forms>
				</view>
				<!-- 验证码区域 -->
			</view>
			<view class="word">
				忘记密码？
			</view>
			<view class="btn">

				<button
					:style="{backgroundImage:(currentBackground === 'bg1'? ImageBg.backgroundImage3 : ImageBg.backgroundImage4 )}"
					@click="clickSign">{{btnItem.item1}}</button>
				<button
					:style="{backgroundImage:(currentBackground === 'bg1'? ImageBg.backgroundImage3 : ImageBg.backgroundImage4 )}"
					@click="clickLogin">{{btnItem.item2}}</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				// 选中背景
				bg: this.$store.state.theme.currentBackground,
				// 选择账号登录
				navId: 'login',
				// 登录输入的表单
				loginForm: {
					username: '',
					password: ''
				},
				// 登录表单的校验规则
				rules: {
					username: {
						rules: [{
							required: true,
							errorMessage: '用户名不能为空'
						}]
					},
					password: {
						rules: [{
							required: true,
							errorMessage: '密码不能为空'
						}]
					}
				},
				// 背景图片
				ImageBg: {
					backgroundImage1: 'url(' + require('@/static/style1/ym1.png') + ')',
					backgroundImage2: 'url(' + require('@/static/style2/ym1.png') + ')',
					backgroundImage3: 'url(' + require('@/static/style1/zh22.png') + ')',
					backgroundImage4: 'url(' + require('@/static/style2/zh22.png') + ')',
				},
				btnItem: {
					item1: '注册',
					item2: '登录'

				},
			}
		},
		methods: {
			// 点击登录 对未登录的表单校验
			clickLogin() {
				this.$refs.loginRef.validate().then(res => {

					console.log('表单数据信息', res);
					uni.showToast({
						title: '登录成功'
					})
					// 登录跳转
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/main/main'
						})
					}, 1000)

				}).catch(err => {
					console.log('表单错误信息', err);
				})
			},
			// 注册
			clickSign() {
				uni.showToast({
					title: "跳转注册"
				})
			}
		},
		computed: {
			...mapState('theme', ['currentBackground'])
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-forms-item {

		margin-bottom: 10rpx !important;
		padding-bottom: 20rpx !important;

		.uni-easyinput {
			color: white !important;
			width: 100%;
			margin: 0 auto;

			.is-input-border {
				background-color: transparent !important;
				outline: none !important;
				border: none !important;
				// border-bottom: 1px solid rgba(255, 141, 255, 0.3) !important;
			}
		}
	}

	.container {
		color: #fff;
		height: 100vh;
		// padding: 100rpx;
		background-color: #11112B;
		position: relative;

		.form {
			height: 52%;
			width: 80%;
			margin: 0 auto;
			position: relative;
			top: 50%;
			transform: translateY(-50%);

			.bg {
				// height: 40%;
				width: 100%;
				// height: 100%;
				// border: 1px solid red;
				padding: 22rpx 0;

				background-repeat: no-repeat;
				background-position: center center;
				background-size: 300px 180.5px;

				.head {
					// color: rgb(237, 155, 255);
					font-size: 35rpx;
					color: rgba(255, 255, 255, 0.5);
					// border: 1px solid red;
					padding: 30rpx 0;
					position: relative;
					// padding-top: 30rpx;
					top: 20rpx;
					width: 80%;
					display: flex;
					justify-content: space-around;
					align-items: center;
					margin: 0 auto;
					line-height: 60rpx;

					// .active1 {
					// 	color: rgb(237, 155, 255);
					// }
				}

				.form-container {
					// width: 80%;
					width: 80%;
					height: 100%;
					// border: 1px solid red;
					margin: 0rpx auto;
					top: -20rpx;
					position: relative;

					.underLine {
						// border-bottom: 1px solid rgba(255, 141, 255, 0.3);
						border-bottom: 1px solid red !important;
					}
				}

				.form-item {
					// padding-left: 0px 40rpx;
					padding: 0 40rpx;
					margin-bottom: 20rpx;
				}


				.last-input {
					padding-bottom: 40rpx;
				}
			}

			.word {
				margin-top: 30rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.btn {
				// color: #fff;
				// border: 1px solid red;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-top: 60rpx;

				button {
					// background: url('@/static/style1/zh22.png');
					background-position: center center;
					background-repeat: no-repeat;
					background-color: transparent;
					color: white;
					width: 200rpx;
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
		}
	}
</style>